package hospital.audit.listener;

import org.hibernate.envers.RevisionListener;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import hospital.audit.model.HospitalRevEntity;

public class HospitalListener implements RevisionListener {

	@Override
	public void newRevision(Object revisionEntity) {
		HospitalRevEntity hospitalRevEntity = (HospitalRevEntity) revisionEntity;
		RequestAttributes ra = RequestContextHolder.getRequestAttributes();
		long currentUserId = (long) ra.getAttribute("currentUserId", RequestAttributes.SCOPE_SESSION);
		hospitalRevEntity.setCurrentUserId(currentUserId);
	}

}
